package org.jeecg.modules.yw.job;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.jeecg.modules.yw.entity.Messages;
import org.jeecg.modules.yw.entity.Order;
import org.jeecg.modules.yw.service.MessagesService;
import org.jeecg.modules.yw.service.OrderService;
import org.jeecg.modules.yw.utils.CommonUtils;
import org.jeecg.modules.yw.utils.DateUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class InitPaymentInformJob implements Job{
	@Resource
	private OrderService orderService;
	
	@Resource
	private MessagesService messageService;
    
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    	
    	// 判断当前是几号
    	String curDate = DateUtils.getDateStr();
    	String day = curDate.substring(8,10);
    	String month = curDate.substring(0,7);
    	String startTime = "";
    	String endTime = "";
    	List<Order> list = new ArrayList<Order>();
    	if (day.equals("10")) {
    		startTime = month + "-01 00:00:00";
    		endTime = DateUtils.getCurrentTimeDateStr();
    		list = orderService.getBaseMapper().selectPaymentOrder(startTime, endTime);
    		
    	} else if (day.equals("20")) {
    		startTime =  month + "-10 09:15:00";
    		endTime = DateUtils.getCurrentTimeDateStr();
    		list = orderService.getBaseMapper().selectPaymentOrder(startTime, endTime);
    		
    	} else {
    		startTime =  month + "-20 09:15:00";
    		endTime = DateUtils.getCurrentTimeDateStr();
    		list = orderService.getBaseMapper().selectPaymentOrder(startTime, endTime);    		
    	}
    	
    	
    	for (Order order : list) {
			String createUserId = order.getCreateUserId();
			String price = order.getFinalPrice();
			String jsTime = orderService.getBaseMapper().getJsTime(createUserId, startTime, endTime);			
			Messages message = new Messages();
	    	message.setId(CommonUtils.getID());
	    	message.setMsgType(2);
	    	message.setNormalMsgType(7);
	    	message.setState(0);
	    	message.setMsgTime(DateUtils.getCurrentTimeDateStr());
	    	message.setCurrentUserId(createUserId);
	    	message.setDelFlag(0);	    	
	    	message.setDealTime(jsTime);
	    	message.setRemark(price);
	    	messageService.save(message);			
		}    	    	
    	//Order order = orderService.getBaseMapper().getOrder(obj.getId());
    	//message.setOrderId(obj.getId());
    	//message.setOrderNo(order.getOrderNo());
    	//message.setYyTime(order.getYyTime());
    	//message.setOwnerAddress(order.getOwnerAddress());
    	
    	
//    	
//    	
//		QueryWrapper<Order> queryWrapper = new QueryWrapper<>();		
//	    queryWrapper.eq("delFlag", 0);
//	    queryWrapper.eq("orderStatus", 10);
//	    List<Order> list = orderService.getBaseMapper().selectList(queryWrapper);	    
//	    for (Order obj : list) {
//	    	
//	    }	    
    }
}
